package com.test;

/**
 * 4 个线程，其中两个线程每次对 j 增加 1 ，另外两个线程对 j 每次减少 1. 写出程序
 * +-+-
 * ++--
 */
public class ThreadTest05 {
    private static volatile int i = 0;

    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 3; j <= 1000; j++) {
                    ThreadTest05.method(j);
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 1001; j <= 2000; j++) {
                    ThreadTest05.method(j);
                }
            }
        }).start();
    }

    public static void method(int x) {
        boolean flag = false;
        for (int j = 2; j <= x - 1; j++) {
            if (x % j == 0) {
                break;
            }
            if (j == x - 1) {
                if (x % j == 0) {

                }else{
                    flag = true;
                }
            }
        }
        if (flag) {
            System.out.println(Thread.currentThread().getName()+"_"+x);
        }
    }
}
